package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baor.dao.FinanceDao;
import com.baor.domain.CarVo;
import com.baor.domain.FinanceVo;
import com.baor.service.FinanceService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class FinanceServiceImpl implements FinanceService {

    @Autowired
    private FinanceDao financeDao;


    @Override
    public AjaxResult<?> financeList(Map<String,Object> params) {
        int pageIndex = (int) params.get("pageIndex");
        int pageSize = (int) params.get("pageSize");
        params.put("pageIndex",(pageIndex - 1)* pageSize);
        Map<String,Object> res = financeDao.findPageCount(params);
        List<FinanceVo> list = financeDao.financeList(params);
        res.put("financeList", list);
        return AjaxResult.success(res);

    }

    @Override
    public AjaxResult<?> list() {
        return AjaxResult.success(financeDao.selectList(null));
    }

    @Override
    public AjaxResult<?> insert(FinanceVo financeVo) {
        int row = financeDao.insert(financeVo);
        if(row > 0) {
            return AjaxResult.success();
        }else{
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> update(FinanceVo financeVo) {
        int row = financeDao.updateById(financeVo);
        if(row > 0) {
            return AjaxResult.success();
        }else{
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult<?> delete(Integer financeId) {
        return AjaxResult.success(financeDao.deleteById(financeId));
    }

    @Override
    public AjaxResult<?> search(FinanceVo financeVo) {
        LambdaQueryWrapper<FinanceVo> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(FinanceVo::getFinanceLicense,financeVo.getFinanceLicense());
        return AjaxResult.success(financeDao.selectList(wrapper));
    }
}
